//
//  TabBarControllerConfig.m
//  LotteryProject
//
//  Created by 阳光 on 17/7/9.
//  Copyright © 2017年 阳光. All rights reserved.
//

#import "TabBarControllerConfig.h"
#import "BaseNavgationViewController.h"
#import "HomeMainViewController.h"
#import "GodMainViewController.h"
#import "ScoreMainViewController.h"
#import "MyMainViewController.h"
#import "FindMainViewController.h"


@interface TabBarControllerConfig ()

@property(nonatomic,strong,readwrite)CYLTabBarController *tabBarController;

@end

@implementation TabBarControllerConfig

-(CYLTabBarController *)tabBarController
{
    if (!_tabBarController) {
        CYLTabBarController *tabBarController=[CYLTabBarController tabBarControllerWithViewControllers:self.createTabBarViewControllers  tabBarItemsAttributes:self.createTabBarItemsAttributes];
        [self customizeTabBarAppearance:tabBarController];
        _tabBarController=tabBarController;
    }
    return _tabBarController;
}

//创建标签栏子控制器数组
-(NSArray *)createTabBarViewControllers
{
    // 首页
    HomeMainViewController *homeVC=[HomeMainViewController new];
    BaseNavgationViewController *homeNaV=[[BaseNavgationViewController alloc]initWithRootViewController:homeVC];

    // 比分
    ScoreMainViewController *scoreVC=[ScoreMainViewController new];
    BaseNavgationViewController *scoreNaV=[[BaseNavgationViewController alloc]initWithRootViewController:scoreVC];

    // 大神擂台
    GodMainViewController *godVC=[GodMainViewController new];
    BaseNavgationViewController *godNaV=[[BaseNavgationViewController alloc]initWithRootViewController:godVC];

    // 发现
    FindMainViewController *findVC=[FindMainViewController new];
    BaseNavgationViewController *findNaV=[[BaseNavgationViewController alloc]initWithRootViewController:findVC];

    // 我的
    MyMainViewController *myVC=[MyMainViewController new];
    BaseNavgationViewController *myNaV=[[BaseNavgationViewController alloc]initWithRootViewController:myVC];

    return @[homeNaV,scoreNaV,godNaV,findNaV,myNaV];
}

//创建标签栏按钮item数组
-(NSArray *)createTabBarItemsAttributes
{
    NSDictionary *homeDic=@{
                            CYLTabBarItemTitle:@"首页",
                            CYLTabBarItemImage:@"btn_home1",
                            CYLTabBarItemSelectedImage:@"btn_home2"
                            };

    NSDictionary *scoreDic=@{
                            CYLTabBarItemTitle:@"比分",
                            CYLTabBarItemImage:@"btn_mom1",
                            CYLTabBarItemSelectedImage:@"btn_mom2"
                            };

    NSDictionary *godDic=@{
                           CYLTabBarItemTitle:@"大神擂台",
                           CYLTabBarItemImage:@"btn_mom1",
                           CYLTabBarItemSelectedImage:@"btn_mom2"
                           };

    NSDictionary *findDic=@{
                            CYLTabBarItemTitle:@"发现",
                            CYLTabBarItemImage:@"btn_mom1",
                            CYLTabBarItemSelectedImage:@"btn_mom2"
                            };

    NSDictionary *myDic=@{
                          CYLTabBarItemTitle:@"我的",
                          CYLTabBarItemImage:@"btn_me2",
                          CYLTabBarItemSelectedImage:@"btn_me2"
                          };

    return @[homeDic,scoreDic,godDic,findDic,myDic];
}

// tabBarItem 的选中和不选中文字属性、背景图片
- (void)customizeTabBarAppearance:(CYLTabBarController *)tabBarController
{
    // 设置文字属性
    UITabBarItem *tabBar=[UITabBarItem appearance];
    [tabBar setTitleTextAttributes:@{
                                     NSForegroundColorAttributeName:Color333333,
                                     NSFontAttributeName:FontNumber(14),
                                     }forState:0];
    [tabBar setTitleTextAttributes:@{
                                     NSForegroundColorAttributeName:MainColor,
                                     NSFontAttributeName:FontNumber(14),
                                     }forState:UIControlStateSelected];
}

@end
